﻿@model IEnumerable<SmallJob.Model.Request>
@{
    var tablename = "TableRequest";
    var numbercolumn = 6;
    var colsname = new[] { "Title", "Category", "User", "Created Date", "Hết hạn" ,"" };
    var curaction = "Index";
    var curcontroller = "Request";
    var configaction = new { details = "Details", del = "Hidden", create = "Create", undel = "UnHidden", edit = "Add" };
    var configtext = new { details = "Details", del = "Hidden", create = "Create", undel = "UnHidden", edit = "Edit" };
    var isfilter = ViewData["filter"] == null ? false : true;
}
<br />
<input type="text" name="search" value="@(isfilter ? ViewData["filter"] : "")" id="inputsearch" />
Search Here, Type and Enter
<div class="div-parent">
    <table class="table table-hover sort table-bordered">
        <thead>
            <tr>
                @for (int i = 0; i < numbercolumn; i++)
                {
                    <th>@colsname[i]
                        <span style="float: right;"><i class="icon-sort"></i></span>
                    </th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @item.Title.Substring(0, item.Title.Length < 40 ? item.Title.Length : 40 )...
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Category.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.AssignedUser.ProperName)
                    </td>
                    <td>
                        @item.CreatedDate.ToString("dd-MM-yyyy hh:mm")
                    </td>
                    <td>
                        @if (item.EndDate < DateTime.Now)
                        {
                            <span class="label label-inverse">@item.EndDate.ToString("dd-MM-yyyy") </span>
                        }
                        else
                        {
                            <span class="label label-success">@item.EndDate.ToString("dd-MM-yyyy")</span>
                        }
                    </td>
                    <td>
                        @Html.ActionLink(@configtext.edit, configaction.edit, new { id = item.ID }) |
                        @Html.ActionLink(@configtext.details, configaction.details, new { id = item.ID }) |
                        @*@if (item.IsDeleted)
                        {
                            <a onclick="undel(this,@item.ID)" href="javascript:;">@configtext.undel</a>
                        }
                        else
                        {
                            <a  onclick="del(this,@item.ID)" href="javascript:;">@configtext.del</a>
                        }*@
                        <a onclick="showbid(@item.ID)" style="cursor:pointer">Bid</a>
                    </td>
                </tr>
            }
        </tbody>

    </table>

    <div class="pagination">
        <ul>
            @{
                var total = Convert.ToInt32(ViewData["total"]);
                var curpage = Convert.ToInt32(ViewData["curpage"]);
                if (curpage > 1)
                {
                <li><a href="/@curcontroller/@curaction/pages/@(curpage - 1)/filter/@(isfilter ? ViewData["filter"] : "")">Prev</a></li>
                }
                for (int i = 1; i <= total; i++)
                {
                    if (i != curpage)
                    {
                <li><a href="/@curcontroller/@curaction/pages/@(i)/filter/@(isfilter ? ViewData["filter"] : "")">@i</a></li>
                    }
                    else
                    {
                <li><a href="/@curcontroller/@curaction/pages/@(i)/filter/@(isfilter ? ViewData["filter"] : "")"><strong>@i</strong></a></li>
                    }

                }
                if (curpage < total)
                {
                <li><a href="/@curcontroller/@curaction/pages/@(curpage + 1)/filter/@(isfilter ? ViewData["filter"] : "")">Next</a></li>
                }
            }
        </ul>
    </div>
</div>
<div id="show-detail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-body" style="max-height: none" id="div-content-detail"></div>
</div>
<script src="@Url.Content("~/Content/js/jquery.tablesorter.min.js")"></script>
<script>
    //table sort
    $(function () {
        $("table.sort").tablesorter();
    });
    $("table").bind("sortStart", function () {
    }).bind("sortEnd", function () {
        $('th.header').each(function () {
            if ($(this).hasClass('headerSortDown')) {
                $(this).find('.icon-sort').addClass('icon-hand-up');
                $(this).find('.icon-sort').removeClass('icon-hand-down');
                console.log('down');

            }
            if ($(this).hasClass('headerSortUp')) {
                $(this).find('.icon-sort').addClass('icon-hand-down');
                $(this).find('.icon-sort').removeClass('icon-hand-up');
                console.log('down');
            }
            if (!$(this).hasClass('headerSortDown') && !$(this).hasClass('headerSortUp')) {
                console.log('none');
                $(this).find('.icon-sort').removeClass('icon-hand-down');
                $(this).find('.icon-sort').removeClass('icon-hand-up');
            }
        });
    });
    function showbid(id) {
        $.post('@Url.Action("Bid","Request")', { id:id}, function (data) {
            $('#div-content-detail').html(data);
            $('#show-detail').modal({ show: true });
        });
    }
</script>
